<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <form id="pForm" class="layui-form" action="" lay-filter="cityForm">
        <div class="layui-form-item">
            <label class="layui-form-label">影院名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="cid" />
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入影院名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">影院的地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" required  lay-verify="required" placeholder="请输入影院的地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">影院的电话</label>
                <div class="layui-input-inline">
                    <input type="tel" name="phone" lay-verify="required|phone" placeholder="请输入影院的电话"  autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">影院的所在城市</label>`
            <div class="layui-input-block">
                <select id="citySelect" name="city.tid" lay-verify="required">

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        $.ajax({
            url: 'yingting/listAllCitys.do',
            dataType: 'json',
            type:'post',
            async:false,
            success: function (data) {
                $.each(data, function (index, item) {
                    console.log("item",item);
                    //option 第一个参数是页面显示的值，第二个参数是传递到后台的值
                    $('#citySelect').append(new Option(item.tname, item.tid));//往下拉菜单里添加元素
                })
                //form.render(); //更新全部表单内容
                form.render("select"); //刷新表单select选择框渲染

            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post("yingting/saveOrUpdate.do",data.field,function (data) {
                if (data.success){
                    layer.close(parentIndex);
                    table.reload("currentTableId");

                }else{
                    layer.msg(error);

                }
            })
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层

            });


            return false;
        });

       /* //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层
                layer.close(index);
                layer.close(parentIndex);

            });


            return false;
        });
*/
    });
</script>